package com.xfcy.blog.controller.system;



import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.xfcy.blog.annotation.OperationLogger;
import com.xfcy.blog.common.R;
import com.xfcy.blog.dto.PhotoAlbumDTO;
import com.xfcy.blog.service.PhotoAlbumService;
import com.xfcy.blog.valid.AddGroup;
import com.xfcy.blog.valid.UpdateGroup;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 相册(PhotoAlbum)表控制层
 *
 * @author 晓风残月Lx
 * @since 2023-04-09 11:03:06
 */
@RestController
@RequestMapping("system/album")
@Api(tags = "后台相册管理")
public class PhotoAlbumController {

    @Resource
    private PhotoAlbumService photoAlbumService;

    @SaCheckLogin
    @GetMapping("/list")
    @ApiOperation(value = "后台相册列表", httpMethod = "GET", response = R.class, notes = "后台相册列表")
    public R list(Integer pageNo, Integer pageSize, String name) {
        return photoAlbumService.listAlbum(pageNo, pageSize, name);
    }

    @OperationLogger(value = "相册详情")
    @GetMapping("/info")
    @SaCheckPermission("/system/album/info")
    @ApiOperation(value = "相册详情", httpMethod = "GET", response = R.class, notes = "相册详情")
    public R info(Integer id) {
        return photoAlbumService.getAlbumById(id);
    }

    @OperationLogger(value = "添加相册")
    @PostMapping("/add")
    @SaCheckPermission("/system/album/add")
    @ApiOperation(value = "添加相册", httpMethod = "POST", response = R.class, notes = "添加相册")
    public R add(@Validated(AddGroup.class) @RequestBody PhotoAlbumDTO photoAlbumDTO) {
        return photoAlbumService.addPhotoAlbum(photoAlbumDTO);
    }

    @OperationLogger(value = "修改相册")
    @PostMapping("/update")
    @SaCheckPermission("/system/album/update")
    @ApiOperation(value = "修改相册", httpMethod = "POST", response = R.class, notes = "修改相册")
    public R update(@Validated(UpdateGroup.class) @RequestBody PhotoAlbumDTO photoAlbumDTO) {
        return photoAlbumService.updatePhotoAlbum(photoAlbumDTO);
    }

    @OperationLogger(value = "删除相册")
    @DeleteMapping(value = "/delete")
    @SaCheckPermission("/system/album/delete")
    @ApiOperation(value = "删除相册", httpMethod = "DELETE", response = R.class, notes = "删除相册")
    public R deleteAlbumById(Integer id) {
        return photoAlbumService.deleteAlbumById(id);
    }

}

